<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_loadSymbolLib"></title>
</head>
<body  style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="toolbar" class="panel panel-primary" style=" position: absolute;top: 10px;right: 10px;text-align: center;z-index: 9999;border-radius: 4px;">
    <div class='panel-heading' id="panelheading">
        <h5 class='panel-title text-center' data-i18n="resources.title_loadSymbolLib"></h5></div>
    <div class='panel-body content' id="panelbodycontent">
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_plot" onclick="plotSymbol()"/>&nbsp; &nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancelMarker" onclick="PlottingDrawCancel()"/>&nbsp; &nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_clear" onclick="PlottingClear()"/>
    </div>
    <div id="popupWin" class="popupWindow" style=" background: #FFF;z-index: 9999;display: block;display: block;top: 400px; height: 150px;">
        <div class='panel'>
            <div class='input-group'>
                <div class="winTitle" style=" margin-left: 20px;font-size: 14px;font-weight: bold;">
                    <span class="title_left" data-i18n="resources.text_symbolLibInfo"></span>
                </div>
            </div>
        </div>
         <div id="symbolLibInfo" class="winContent" style="  padding: 5px;overflow-y: auto;height: 220px;overflow-y:auto;height:250px;">
        </div>
    </div>
</div>
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
<script type="text/javascript" include="iclient9-leaflet-css,iclient9-plot-leaflet" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "http://iclsvr.supermap.io";
    var url = host + "/iserver/services/map-china400/rest/maps/China_4326";
    var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";
    var map,symbolLibManager;
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: [35,104],
        maxZoom: 18,
        zoom: 3
    });
    L.supermap.tiledMapLayer(url).addTo(map);
    var plottingLayer = L.supermap.plotting.plottingLayer("plot", serverUrl);
    plottingLayer.addTo(map);
    var drawControl = L.supermap.plotting.drawControl(plottingLayer);
    drawControl.addTo(map);
    var editControl = L.supermap.plotting.editControl();
    editControl.addTo(map);
    var plotting = L.supermap.plotting.getControl(map, serverUrl);
    function loadSymbolLib(){
        symbolLibManager = plotting.getSymbolLibManager();
        symbolLibManager.on(SuperMap.Plot.Event.initializecompleted,showSymbolLibInfo);
        symbolLibManager.initializeAsync();
    }
    function showSymbolLibInfo(result) {
        document.all.symbolLibInfo.innerHTML = "";

        if (0 === result.length) {
            return;
        }

        var symbolLib = symbolLibManager.getSymbolLibByIndex(0);


        //获取选中的对象
        var container = document.getElementById("symbolLibInfo");
        var table = document.createElement("table");
        var body = document.createElement("tbody");
        table.setAttribute("border", "1");
        table.setAttribute("borderColor", "black");
        table.setAttribute("width", "100%");

        //标号库名称
        var tr_SymbolLibName = document.createElement("tr");

        var tdName_SymbolLibName = document.createElement("td");
        var textName_SymbolLibName = document.createTextNode("标号库名称");
        tdName_SymbolLibName.appendChild(textName_SymbolLibName);
        tr_SymbolLibName.appendChild(tdName_SymbolLibName);

        var tdValue_SymbolLibName = document.createElement("td");
        var textValue_SymbolLibName = document.createTextNode(symbolLib.getSymbolLibName());
        tdValue_SymbolLibName.appendChild(textValue_SymbolLibName);
        tr_SymbolLibName.appendChild(tdValue_SymbolLibName);

        body.appendChild(tr_SymbolLibName);

        //标号库ID
        var tr_SymbolLibID = document.createElement("tr");

        var tdName_SymbolLibID = document.createElement("td");
        var textName_SymbolLibID = document.createTextNode("标号库ID");
        tdName_SymbolLibID.appendChild(textName_SymbolLibID);
        tr_SymbolLibID.appendChild(tdName_SymbolLibID);

        var tdValue_SymbolLibID = document.createElement("td");
        var textValue_SymbolLibID = document.createTextNode(symbolLib.getSymbolLibID());
        tdValue_SymbolLibID.appendChild(textValue_SymbolLibID);
        tr_SymbolLibID.appendChild(tdValue_SymbolLibID);

        body.appendChild(tr_SymbolLibID);

        //标号库标号个数
        var tr_SymbolCount = document.createElement("tr");

        var tdName_SymbolCount = document.createElement("td");
        var textName_SymbolCount = document.createTextNode("标号个数");
        tdName_SymbolCount.appendChild(textName_SymbolCount);
        tr_SymbolCount.appendChild(tdName_SymbolCount);

        var tdValue_SymbolCount = document.createElement("td");
        var textValue_SymbolCount = document.createTextNode(symbolLib.getSymbolCount());
        tdValue_SymbolCount.appendChild(textValue_SymbolCount);
        tr_SymbolCount.appendChild(tdValue_SymbolCount);

        body.appendChild(tr_SymbolCount);


        table.appendChild(body);
        container.appendChild(table);
    }
    function getCode(symbolInfo) {
        var nCode = -1;
        while (symbolInfo.symbolNodeType === "SYMBOL_GROUP") {
            symbolInfo = symbolInfo.childNodes[0];
        }

        nCode = symbolInfo.symbolCode;

        return nCode;
    }
    function getFirstSymbol() {
        var nCode = -1;
        var symbolLib = symbolLibManager.getSymbolLibByIndex(0);
        if (null === symbolLib) {
            drawGraphicObject.deactivate();
            return nCode;
        }

        var rootSymbolInfo = symbolLib.getRootSymbolInfo();

        var i = 0;
        nCode = getCode(rootSymbolInfo.childNodes[i]);
        while (-1 === nCode) {
            i++;
            nCode = getCode(rootSymbolInfo.childNodes[i]);
        }

        return nCode;
    }
    function plotSymbol(){
        var symbolLib = symbolLibManager.getSymbolLibByIndex(0);
        if (null === symbolLib) {
            drawControl.handler.disable();
            return;
        }
        drawControl.handler.libID = symbolLib.getSymbolLibID();
        drawControl.handler.code = getFirstSymbol();
        drawControl.handler.serverUrl = serverUrl;
        drawControl.handler.enable();
    }
    function PlottingDrawCancel(){
        drawControl.handler.disable();
    }
    function PlottingClear(){
        plottingLayer.removeAllFeatures();
    }
    window.onload = function(){
        loadSymbolLib();
    };
    $(document).ready(function(){
        $('#panelheading').click(function(){
            $('#panelbodycontent').toggle();
            $('#popupWin').toggle();
        });
    });
</script>
</body>
</html>